#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN DATA ABSTRACTION LAYER version 1

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Using directives
using System;
#endregion

namespace Thn.Data.Settings
{
    /// <summary>
    /// Provides a convenient place to config Data Access Layer tier
    /// </summary>
    public class DataTierSettings
    {
        #region Auto Publish Error
        private bool mAutoPublishError = true;
        /// <summary>
        /// Publishes exceptions occurs in DAL tier automatically.
        /// <para>Default is true</para>
        /// </summary>
        public static bool AutoPublishError
        {
            get { return Instance.mAutoPublishError; }
            set { Instance.mAutoPublishError = value; }
        }
        #endregion

        #region Silent Error
        private bool mSilentError;
        /// <summary>
        /// When true, exceptions occurs in DAL tier will not be thrown. (They will still be published if AutoPublishError is true)
        /// <para>Default is false</para>
        /// </summary>
        public static bool SilentError
        {
            get { return Instance.mSilentError; }
            set { Instance.mSilentError = value; }
        }
        #endregion

        #region Log Command
#if DEBUG
        private bool mLogCommand = true;
#else
        private bool mLogCommand = false;
#endif
        /// <summary>
        /// When true, write query command and parameter to logs for debugging purposes
        /// </summary>
        public static bool LogCommand
        {
            get { return Instance.mLogCommand; }
            set { Instance.mLogCommand = value; }
        }
        #endregion            

        #region Instance
		/// <summary>
		/// Static variable for thread locking
		/// </summary>
		static object SyncRoot = new object();
		
		/// <summary>
		/// Actual static variable for Instance
		/// </summary>
		static DataTierSettings mInstance = null;
		
		/// <summary>
		/// Gets the static instance of this class
		/// </summary>
		static DataTierSettings Instance
		{
			get
			{
				if (mInstance == null)
				{
					//initialize new instance
					DataTierSettings tmp = new DataTierSettings();
					
					//assign to static variable. Lock root for thread-safe locking
					lock (SyncRoot)
					{
						mInstance = tmp;
					}
				}

				return mInstance;
			}
		}
		
		//private constructor
		DataTierSettings() { }
		#endregion
    }
}
